<?php
/**
 * hognyi @taoding 2018.11.19
 *
 *
 */
namespace App\Logic;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Http\Resources\Bill as BillResource;
use App\Models\Agent;
use App\Models\Bill;
use App\Models\Linkman;
use App\Models\SysUser;
use PhpParser\Node\Stmt\TryCatch;
use Illuminate\Support\Facades\Hash;

class BillLogic
{
	
	/**
	 * 表单数据
	 * @var array
	 */
	private $_post_data = array();
	
		
	public function __construct()
	{
		
	}
	
	// 分页获取账单列表
	static public function getBillList($where, $page = 1, $limit = 20,$start='',$end='')
	{
        $bill_list = BillResource::collection(Bill::where($where)->orderBy('sort', 'desc')->paginate($limit))->additional(['code' =>200,'status' => 'success']);
        
        foreach($bill_list as $bill){
        	$bill->consume_category = Bill::getLockStateDisplayMap()[$bill->consume_category];
	    }
	    
	    return $bill_list;
	}
	
	static public function getBillExportData($where){
		$bill_info = Bill::where($where)->select('consume_category','operate_time','consume_amount','operate_description')->get()->toArray();
		//dd($bill_info);
		$data = array();
		foreach($bill_info as $key=>$val){
			$data[$key] = $val;
			$data[$key]['consume_category'] = Bill::getLockStateDisplayMap()[$val['consume_category']];
		}
		return $data;
	}
	
}